<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>

<body>
  <script>
    // 对象的解构赋值
    let res = { name: "王", age: 18 }
    // let name = res.name;
    // let age = res.age;
    // 1.基本解构赋值
    // let { name, age } = res;
    let { age, name, sex } = { name: "王", sex: "男", age: 18 }
    console.log(name, age, sex)
    // 2.可嵌套赋值  x=hello   y=world

    let { p: [x, { y }] } = { p: ['hello', { y: 'world' }] }
    console.log(x, y)
    // 3剩余运算符
    let { a, b, ...rest } = { a: 10, b: 20, c: 30, d: 40 }
    console.log(rest)
    //4.es6 的函数使用剩余运算符
    function say(a, b, ...rest) {
      console.log(a)
      console.log(b)
      console.log(rest) // [[1,2,3], "哈哈", true]
      console.log(arguments)
    }
    say(18, 28, [1, 2, 3], "哈哈", true)

  </script>
</body>

</html>